// 引入mock 生成数据
import Mock from 'mockjs'
import { childrenUsers, teacherUSers } from '@/public/list'
var data = Mock.mock({
    'token': '@guid()',
})
// 创建接口
Mock.mock('/login', 'post', (options) => {
    const parse = JSON.parse(options.body.replace(/\s+/g, ''))
    if (parse.username.startsWith('XS')) {
        const user = childrenUsers.find(item => item.username === parse.username)
        if (user) {
            if (parse.username === user.username && parse.password === user.password) {
                return ({
                    code: 200,
                    message: '登录成功',
                    data
                })
            } else {
                return {
                    code: 109,
                    message: '用户名或密码错误',
                }
            }
        } else {
            return {
                code: 108,
                message: '该用户未注册',
            }
        }
    } else {
        const user = teacherUSers.find(item => item.username === parse.username)
        if (user) {
            if (parse.username === user.username && parse.password === user.password) {
                return ({
                    code: 200,
                    message: '登录成功',
                    data
                })
            } else {
                return {
                    code: 109,
                    message: '用户名或密码错误',
                }
            }
        } else {
            return {
                code: 108,
                message: '该用户未注册',
            }
        }
    }
})